<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
<script src="//geoip-js.com/js/apis/geoip2/v2.1/geoip2.js" type="text/javascript"></script>

<script>
    $(function(){
        //需要自定义填写屏蔽词SensitiveWords
        //需要自定义填写跳转链接url sendRequest(url)

        //真实地址returnCitySN["cname"]
        //真实IPreturnCitySN["cip"];
        //禁止地址集合
        var SensitiveWords = new Array();
        SensitiveWords[0]="新加坡";
        SensitiveWords[1]="湖北";
        var WordsType = 0;

        fillInPage();
//        returnCitySN["cname"] = cityName;
//        //查询是否是禁止
//        if(in_array(returnCitySN["cname"],SensitiveWords) == true){
//            WordsType = 1;
//        }
//        switch (WordsType) {
//            case 1:
//                sendRequest("/account/login");
//                break;
//            case 2:
//                sendRequest("/account/login");
//                break;
//            default:
//        }
    });
    function createXMLHttpRequest(){
        if(window.XMLHttpRequest){
            XMLHttpR = new XMLHttpRequest();
        }else if(window.ActiveXObject){
            try{
                XMLHttpR = new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e){
                try{
                    XMLHttpR = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(e){
                }
            }
        }
    }
    function sendRequest(url){
        createXMLHttpRequest();
        XMLHttpR.open("GET",url,true);
        XMLHttpR.onreadystatechange = processResponse;
        XMLHttpR.send(null);
    }
    function processResponse(){
        if(XMLHttpR.readyState === 4 && XMLHttpR.status === 200){
            document.write(XMLHttpR.responseText);
        }
    }
    function in_array(search,array){
        for(var i in array){
            if(search.indexOf(array[i]) != -1){
                return true;
            }
        }
        return false;
    };
    var fillInPage = (function() {
        var updateCityText = function(geoipResponse) {

            /*
             * It's possible that we won't have any names for this city.
             * For language codes with a special character such as pt-BR,
             * replace names.en with names['pt-BR'].
             */
            var cityName = geoipResponse.city.names.en || 'your city';
            console.log('cityName',cityName);
        };

        var onSuccess = function(geoipResponse) {
            updateCityText(geoipResponse);
        };

        // If we get an error, we will display an error message
        var onError = function(error) {
//            document.getElementById('city').innerHTML = 'an error!  Please try again..'
        };

        return function() {
            if (typeof geoip2 !== 'undefined') {
                geoip2.city(onSuccess, onError);
            } else {
//                document.getElementById('city').innerHTML = 'a browser that blocks GeoIP2 requests'
            }
        };
    }());
</script>
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    {:token()}
    <div class="alert alert-warning-light">
        {:__('Category warmtips')}
    </div>

    <div class="form-group">
        <label for="c-type" class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
        <div class="col-xs-12 col-sm-8">

            <select id="c-type" data-rule="required" class="form-control selectpicker" name="row[type]">
                {foreach name="typeList" item="vo"}
                <option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
                {/foreach}
            </select>

        </div>
    </div>
    <div class="form-group">
        <label for="c-pid" class="control-label col-xs-12 col-sm-2">{:__('Pid')}:</label>
        <div class="col-xs-12 col-sm-8">

            <select id="c-pid" data-rule="required" class="form-control selectpicker" name="row[pid]">
                {foreach name="parentList" item="vo"}
                <option data-type="{$vo.type}" value="{$key}" {in name="key" value=""}selected{/in}>{$vo.name}</option>
                {/foreach}
            </select>

        </div>
    </div>
    <div class="form-group">
        <label for="c-name" class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="">
        </div>
    </div>
    <div class="form-group">
        <label for="c-nickname" class="control-label col-xs-12 col-sm-2">{:__('Nickname')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-nickname" data-rule="required" class="form-control" name="row[nickname]" type="text" value="">
        </div>
    </div>
    <div class="form-group">
        <label for="c-flag" class="control-label col-xs-12 col-sm-2">{:__('Flag')}:</label>
        <div class="col-xs-12 col-sm-8">

            <select  id="c-flag" class="form-control selectpicker" multiple="" name="row[flag][]">
                {foreach name="flagList" item="vo"}
                <option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
                {/foreach}
            </select>

        </div>
    </div>
    <div class="form-group">
        <label for="c-image" class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-image" class="form-control" size="35" name="row[image]" type="text" value="">
                <div class="input-group-addon no-border no-padding">
                    <span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                    <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
                </div>
                <span class="msg-box n-right"></span>
            </div>
            <ul class="row list-inline faupload-preview" id="p-image"></ul>
        </div>
    </div>
    <div class="form-group">
        <label for="c-keywords" class="control-label col-xs-12 col-sm-2">{:__('Keywords')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-keywords" class="form-control" name="row[keywords]" type="text" value="">
        </div>
    </div>
    <div class="form-group">
        <label for="c-description" class="control-label col-xs-12 col-sm-2">{:__('Description')}:</label>
        <div class="col-xs-12 col-sm-8">
            <textarea id="c-description" class="form-control" name="row[description]"></textarea>
        </div>
    </div>
    <div class="form-group">
        <label for="c-weigh" class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-weigh" class="form-control" name="row[weigh]" type="number" value="0">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
        <div class="col-xs-12 col-sm-8">
            {:build_radios('row[status]', ['normal'=>__('Normal'), 'hidden'=>__('Hidden')])}
        </div>
    </div>
    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>
</form>
